#!/usr/bin/env python
#-*- coding:utf-8 -*-

# file:book_regulatorviews.py
# author:ytytyt
# datetime:2021/6/27 16:04
# software: PyCharm
"""
图书管理的蓝图定义
"""
# import module your need
from flask import Blueprint
from flask import render_template, request, redirect

#url_prefix表示要以类似于127.0.0.1/url_prefix/路由的方式进行访问
book_regulator_bp = Blueprint("book_regulator", __name__, url_prefix="/book")  # 初始化蓝图

@book_regulator_bp.route('/')
def home():

    return "blueprint test succeesfully!"

#定义添加处理路由
@book_regulator_bp.route('/add',methods = ['GET','POST'])
def add():
    from controller.readerController import ReaderController
    # params = request.args if request.method == 'GET' else request.form
    # title = params.get('title')
    # print(title)
    kwargs = {
        'name': "小明",
        'password':"123456",
        'sex':"男"

    }
    ReaderController.add(**kwargs)
    return "add data try try"
    # return redirect('/todolist/index')
    # return render_template('index.html', todolist=res['data'])
    # return 'this is my web-flask index page!'

# 定义删除数据路由
# @todolist_bp.route('/delete/<AutoID>',methods=['POST','GET','DELETE'])
# def delete(AutoID):
#     from controller.toDolistController import ToDoListController
#     kwargs = {
#         'AutoID':AutoID
#     }
#     ToDoListController.delete(**kwargs)
#     return redirect('/todolist/index')
#
# #定义查询方法
# @todolist_bp.route('/search',methods=['POST'])
# def search():
#     from controller.toDolistController import ToDoListController
#     params = request.args if request.method == 'GET' else request.form
#     title = params.get('title')
#     print(title)
#     kwargs = {
#         'Title': title,
#     }
#     res = ToDoListController.query(**kwargs)
#     return render_template('index.html', todolist=res['data'])